package com.wbu.estatemanagement.controller;


import com.wbu.estatemanagement.common.MessageConstant;
import com.wbu.estatemanagement.common.Result;
import com.wbu.estatemanagement.common.StatusCode;
import com.wbu.estatemanagement.domain.Admin;
import com.wbu.estatemanagement.domain.User;
import com.wbu.estatemanagement.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("admin")
public class AdminController {

    @Autowired
    AdminService adminService;


    @PostMapping("/adminInfo")
    public Result adminInfo(HttpSession httpSession){
        Admin sessionAdmin= (Admin) httpSession.getAttribute("admin");
        if(sessionAdmin==null){
            return new Result(false, StatusCode.ERROR, MessageConstant.FAIL);
        }
        Integer adminId = sessionAdmin.getId();
        Admin admin=adminService.findAdmin(adminId);
        if (admin.getSex().equals("0")){
            admin.setSex("男");
        }
        return new Result(true, StatusCode.OK, MessageConstant.SUCCESS,admin);
    }

}
